home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 21 Ambient Occlusion / Ssao / Shaders / Shadows.hlsl < prev    next >
Encoding:
Text File  |  2016-03-02  |  1.8 KB  |  61 lines

  1. //***************************************************************************************
  2. // Shadows.hlsl by Frank Luna (C) 2015 All Rights Reserved.
  3. //***************************************************************************************
  4.  
  5. // Include common HLSL code.
  6. #include "Common.hlsl"
  7.  
  8. struct VertexIn
  9. {
  10.     float3 PosL    : POSITION;
  11.     float2 TexC    : TEXCOORD;
  12. };
  13.  
  14. struct VertexOut
  15. {
  16.     float4 PosH    : SV_POSITION;
  17.     float2 TexC    : TEXCOORD;
  18. };
  19.  
  20. VertexOut VS(VertexIn vin)
  21. {
  22.     VertexOut vout = (VertexOut)0.0f;
  23.  
  24.     MaterialData matData = gMaterialData[gMaterialIndex];
  25.     
  26.     // Transform to world space.
  27.     float4 posW = mul(float4(vin.PosL, 1.0f), gWorld);
  28.  
  29.     // Transform to homogeneous clip space.
  30.     vout.PosH = mul(posW, gViewProj);
  31.     
  32.     // Output vertex attributes for interpolation across triangle.
  33.     float4 texC = mul(float4(vin.TexC, 0.0f, 1.0f), gTexTransform);
  34.     vout.TexC = mul(texC, matData.MatTransform).xy;
  35.     
  36.     return vout;
  37. }
  38.  
  39. // This is only used for alpha cut out geometry, so that shadows 
  40. // show up correctly.  Geometry that does not need to sample a
  41. // texture can use a NULL pixel shader for depth pass.
  42. void PS(VertexOut pin) 
  43. {
  44.     // Fetch the material data.
  45.     MaterialData matData = gMaterialData[gMaterialIndex];
  46.     float4 diffuseAlbedo = matData.DiffuseAlbedo;
  47.     uint diffuseMapIndex = matData.DiffuseMapIndex;
  48.     
  49.     // Dynamically look up the texture in the array.
  50.     diffuseAlbedo *= gTextureMaps[diffuseMapIndex].Sample(gsamAnisotropicWrap, pin.TexC);
  51.  
  52. #ifdef ALPHA_TEST
  53.     // Discard pixel if texture alpha < 0.1.  We do this test as soon 
  54.     // as possible in the shader so that we can potentially exit the
  55.     // shader early, thereby skipping the rest of the shader code.
  56.     clip(diffuseAlbedo.a - 0.1f);
  57. #endif
  58. }
  59.  
  60.  
  61.